Allow pciback to be built as a module.
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Wed, 8 Mar 2006 17:41:12 +0000 (18:41 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Wed, 8 Mar 2006 17:41:12 +0000 (18:41 +0100)
From: Jan Beulich
Signed-off-by: Keir Fraser <keir@xensource.com>
linux-2.6-xen-sparse/drivers/xen/Kconfig
linux-2.6-xen-sparse/drivers/xen/pciback/Makefile
linux-2.6-xen-sparse/drivers/xen/pciback/conf_space_header.c
linux-2.6-xen-sparse/drivers/xen/pciback/pci_stub.c
linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h
linux-2.6-xen-sparse/drivers/xen/pciback/pciback_ops.c
linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c

index 7a6a569a57444a095f53ae79fa28ab0b99ae5629..eaf774af550a1201ddd4a2920c4be1c1d2975097 100644 (file)
@@ -30,9 +30,9 @@ config XEN_UNPRIVILEGED_GUEST
        default !XEN_PRIVILEGED_GUEST
 
 config XEN_PCIDEV_BACKEND
-       bool "PCI device backend driver"
-       select PCI
-       default y if XEN_PRIVILEGED_GUEST
+       tristate "PCI device backend driver"
+       depends PCI
+       default XEN_PRIVILEGED_GUEST
        help
          The PCI device backend driver allows the kernel to export arbitrary
          PCI devices to other guests.
index e031caa03fca81a0845ce7ab50932c2ee41ed9b4..bfe77e64d7c731e06dd0b13ece3fac63b7d5024a 100644 (file)
@@ -1,9 +1,9 @@
-obj-y += pciback.o
+obj-$(CONFIG_XEN_PCIDEV_BACKEND) += pciback.o
 
 pciback-y := pci_stub.o pciback_ops.o xenbus.o
 pciback-y += conf_space.o conf_space_header.o
-pciback-${CONFIG_XEN_PCIDEV_BACKEND_VPCI} += vpci.o
-pciback-${CONFIG_XEN_PCIDEV_BACKEND_PASS} += passthrough.o
+pciback-$(CONFIG_XEN_PCIDEV_BACKEND_VPCI) += vpci.o
+pciback-$(CONFIG_XEN_PCIDEV_BACKEND_PASS) += passthrough.o
 
 ifeq ($(CONFIG_XEN_PCIDEV_BE_DEBUG),y)
 EXTRA_CFLAGS += -DDEBUG
index 17607d3bf4fe5c1baed571858ac5961db1074288..0b9fce38bcab8bc2115136ced7cd639888dcc515 100644 (file)
@@ -24,21 +24,19 @@ static int command_write(struct pci_dev *dev, int offset, u16 value, void *data)
                if (unlikely(verbose_request))
                        printk(KERN_DEBUG "pciback: %s: enable\n",
                               pci_name(dev));
-               dev->is_enabled = 1;
-               pcibios_enable_device(dev, (1 << PCI_NUM_RESOURCES) - 1);
+               pci_enable_device(dev);
        } else if (dev->is_enabled && !is_enable_cmd(value)) {
                if (unlikely(verbose_request))
                        printk(KERN_DEBUG "pciback: %s: disable\n",
                               pci_name(dev));
-               pciback_disable_device(dev);
+               pci_disable_device(dev);
        }
 
        if (!dev->is_busmaster && is_master_cmd(value)) {
                if (unlikely(verbose_request))
                        printk(KERN_DEBUG "pciback: %s: set bus master\n",
                               pci_name(dev));
-               dev->is_busmaster = 1;
-               pcibios_set_master(dev);
+               pci_set_master(dev);
        }
 
        if (value & PCI_COMMAND_INVALIDATE) {
index aa76d75d847ff6f877bea82b6635ffbb0535015b..2e0b8a0110b28b8031e93a02e15aaf709a4fa7ff 100644 (file)
@@ -208,8 +208,6 @@ static int __init pcistub_init_devices_late(void)
        return 0;
 }
 
-device_initcall(pcistub_init_devices_late);
-
 static int __devinit pcistub_seize(struct pci_dev *dev)
 {
        struct pci_stub_device *psdev;
@@ -367,6 +365,7 @@ static int __init pcistub_init(void)
        return -EINVAL;
 }
 
+#ifndef MODULE
 /*
  * fs_initcall happens before device_initcall
  * so pciback *should* get called first (b/c we 
@@ -375,3 +374,34 @@ static int __init pcistub_init(void)
  * driver to register)
  */
 fs_initcall(pcistub_init);
+#endif
+
+static int __init pciback_init(void)
+{
+#ifndef MODULE
+       int err;
+
+       err = pcistub_init();
+       if (err < 0)
+               return err;
+#endif
+
+       if (list_empty(&pci_stub_device_ids))
+               return -ENODEV;
+       pcistub_init_devices_late();
+       pciback_xenbus_register();
+
+       __unsafe(THIS_MODULE);
+
+       return 0;
+}
+
+static void pciback_cleanup(void)
+{
+       BUG();
+}
+
+module_init(pciback_init);
+module_exit(pciback_cleanup);
+
+MODULE_LICENSE("Dual BSD/GPL");
index a1f408bf3a3832336cb3f19b56cddfcb2eeb0288..f82ece4a2cf4047426afd604c14d15436f746021 100644 (file)
@@ -43,7 +43,6 @@ struct pci_dev *pcistub_get_pci_dev(struct pci_dev *dev);
 void pcistub_put_pci_dev(struct pci_dev *dev);
 
 /* Ensure a device is turned off or reset */
-void pciback_disable_device(struct pci_dev *dev);
 void pciback_reset_device(struct pci_dev *pdev);
 
 /* Access a virtual configuration space for a PCI device */
@@ -69,5 +68,7 @@ void pciback_release_devices(struct pciback_device *pdev);
 /* Handles events from front-end */
 irqreturn_t pciback_handle_event(int irq, void *dev_id, struct pt_regs *regs);
 
+int pciback_xenbus_register(void);
+
 extern int verbose_request;
 #endif
index 9019608ab7f65167a6bdc0a4eb26d5a3a61145ec..dcfd746a0f9e9a070e5d5ad13a720c29b32f7afb 100644 (file)
 int verbose_request = 0;
 module_param(verbose_request, int, 0644);
 
-/* For those architectures without a pcibios_disable_device */
-void __attribute__ ((weak)) pcibios_disable_device(struct pci_dev *dev) { }
-
-void pciback_disable_device(struct pci_dev *dev)
-{
-       if (dev->is_enabled) {
-               dev->is_enabled = 0;
-               pcibios_disable_device(dev);
-       }
-}
-
 /* Ensure a device is "turned off" and ready to be exported.
  * This also sets up the device's private data to keep track of what should
  * be in the base address registers (BARs) so that we can keep the
@@ -32,7 +21,7 @@ void pciback_reset_device(struct pci_dev *dev)
 
        /* Disable devices (but not bridges) */
        if (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) {
-               pciback_disable_device(dev);
+               pci_disable_device(dev);
 
                pci_write_config_word(dev, PCI_COMMAND, 0);
 
index b3dc7fb435bfc9bdf778460298efb95696d53888..1df5feacdc374df96e249148e60dec2b95b58565 100644 (file)
@@ -430,10 +430,7 @@ static struct xenbus_driver xenbus_pciback_driver = {
        .otherend_changed       = pciback_frontend_changed,
 };
 
-static __init int pciback_xenbus_register(void)
+int __init pciback_xenbus_register(void)
 {
        return xenbus_register_backend(&xenbus_pciback_driver);
 }
-
-/* Must only initialize our xenbus driver after the pcistub driver */
-device_initcall(pciback_xenbus_register);